home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / drivesex / drivesex.asm < prev    next >
Assembly Source File  |  1994-07-06  |  5KB  |  135 lines

  1. ; DRIVESEX.ASM - Drive existence detection      July 6th, 1994
  2. ; Code by       : Lee Hamel (hamell@cs.pdx.edu)
  3. ; Partial credit: Paul Schlyter
  4. ;
  5. ; Goes through drives A-Z and determines if they:
  6. ; 1) Exist
  7. ; 2) Are removable or fixed
  8. ; 3) Are local, remote, or shared
  9. ; 4) Are a floppy, hard, RAM, subst, or CD-ROM drive
  10. ;
  11. ; Callable from C as: void Drives_Exist(void);
  12.  
  13. .model small
  14. .286
  15.  
  16. DRIVEEXIST      EQU     1
  17.  
  18. REMOVEDRV       EQU     0
  19. FIXEDDRV        EQU     1
  20.  
  21. LOCALDRV        EQU     0
  22. REMOTEDRV       EQU     1
  23. SHAREDRV        EQU     2
  24.  
  25. FLOPPY          EQU     0
  26. HARD            EQU     1
  27. RAM             EQU     2
  28. SUBST           EQU     3
  29. CDROM           EQU     4
  30.  
  31. .data
  32. PUBLIC  _drives
  33.         _drives         db      26 dup(0,1,0,1)
  34.         ; default to not exist, fixed, local, hard drive
  35.  
  36. .code
  37.  
  38.                         PUBLIC  _Drives_Exist
  39. _Drives_Exist           PROC    NEAR
  40.                 pusha
  41.                 push    es
  42.  
  43.                 mov     ah,19h
  44.                 int     21h             ; get start drive
  45.                 push    ax              ; save start drive
  46.  
  47.                 mov     ax,40h
  48.                 mov     es,ax
  49.                 mov     bh,es:[10h]     ; 40:10h is # of floppies-1
  50.                 shr     bh,6
  51.                 inc     bh              ; # of actual floppy drives
  52.                 mov     bl,1
  53.                 mov     di,offset _drives
  54. nextchkfloppy:  mov     ax,4409h        ; check if drive exists
  55.                 int     21h
  56.                 jc      nextsetfloppy
  57.                 test    dh,10000000b    ; check if SUBST drive
  58.                 jz      chkfloppy
  59.                 dec     bh              ; dec actual drive count
  60.                 mov     byte ptr [di+3],SUBST
  61. setfloppyexist: mov     byte ptr [di],DRIVEEXIST
  62.                 jmp     nextsetfloppy
  63. chkfloppy:      dec     bh              ; dec actual drive count
  64.                 js      nextsetfloppy
  65.                 mov     byte ptr [di+1],REMOVEDRV
  66.                 mov     byte ptr [di+3],FLOPPY
  67.                 jmp     setfloppyexist
  68. nextsetfloppy:  add     di,4
  69.                 inc     bl
  70.                 cmp     bl,2            ; if B then jump back
  71.                 je      nextchkfloppy
  72.  
  73.                 mov     ch,24           ; loop 24 times (drives C - Z)
  74.                 mov     cl,3            ; start at C:
  75. drivechkloop:   mov     ax,4409h        ; check if drive exists
  76.                 mov     bl,cl           ; set drive letter
  77.                 int     21h             ; 0 = default, 1 = A:, etc.
  78.                 jc      nextsetdrv
  79.                 mov     byte ptr [di],DRIVEEXIST
  80.                 mov     ax,4408h        ; check if removable
  81.                 int     21h
  82.                 mov     byte ptr [di+1],al      ; set REMOVABLE or FIXED
  83.                 mov     bx,dx
  84.                 mov     dl,dh
  85.                 shr     dl,7
  86.                 and     dh,00010000b
  87.                 shr     dh,4
  88.                 mov     byte ptr [di+2],dh      ; set REMOTE or LOCAL
  89.                 or      dl,dl                   ; if not SUBST, then jump
  90.                 jz      chkremote
  91.                 mov     byte ptr [di+3],SUBST
  92.                 jmp     nextsetdrv
  93.  
  94. chkremote:      cmp     dh,REMOTEDRV    ; if REMOTE, then check for CD ROM
  95.                 je      chkcdrom
  96.  
  97.                 test    bh,00000010b    ; sharable?
  98.                 jz      drivenoshare
  99.                 mov     byte ptr [di+2],SHAREDRV
  100. drivenoshare:   test    bl,00000010b    ; RAM drive?
  101.                 jnz     nextsetdrv
  102.                 mov     byte ptr [di+3],RAM
  103.                 jmp     nextsetdrv
  104.  
  105. chkcdrom:       push    cx
  106.                 mov     ax,1500h
  107.                 xor     bx,bx
  108.                 int     2fh
  109.                 pop     cx
  110.                 or      bx,bx           ; MSCDEX driver found?
  111.                 jz      nextsetdrv      ; if not, jump to next drive setup
  112.                 mov     ax,150bh
  113.                 dec     cl              ; 0=A:, etc.
  114.                 int     2fh
  115.                 inc     cl
  116.                 or      ax,ax
  117.                 jz      nextsetdrv      ; drive supported by MSCDEX?
  118.                 mov     byte ptr [di+3],CDROM
  119.  
  120. nextsetdrv:     add     di,4
  121.                 inc     cl
  122.                 dec     ch
  123.                 jnz     drivechkloop
  124.  
  125.                 pop     dx
  126.                 mov     ah,0eh
  127.                 int     21h             ; reset start drive
  128.  
  129.                 pop     es
  130.                 popa
  131.                 ret
  132. _Drives_Exist           ENDP
  133.  
  134.                         END
  135.